/*
 * Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package tools;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class MyXxxx {

    private static final String URL =
            "jdbc:mysql://localhost:3306/npi?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "root";

    public static void main(String[] args) {
        // 使用 FastAutoGenerator 快速配置代码生成器
        FastAutoGenerator.create(URL, "root", "root")
                .globalConfig(
                        builder -> {
                            builder.author("段静迪,duanjingdi@163.com") // 设置作者
                                    .outputDir(
                                            "D:\\Work\\tyut\\y24g3\\myboot\\src\\main\\java"); // 输出目录
                        })
                .packageConfig(
                        builder -> {
                            builder.parent("com.neusoft.tyut.npi.admin") // 设置父包名
                                    .entity("entity") // 设置实体类包名
                                    .mapper("mapper") // 设置 Mapper 接口包名
                                    .service("service") // 设置 Service 接口包名
                                    .serviceImpl("service.impl") // 设置 Service 实现类包名
                                    .pathInfo(
                                            Collections.singletonMap(
                                                    OutputFile.xml,
                                                    "D:\\Work\\tyut\\y24g3\\myboot\\src\\main\\resources\\mapper"));
                            //                                    .xml("mappers"); // 设置 Mapper XML
                            // 文件包名
                        })
                .strategyConfig(
                        builder -> {
                            builder.addInclude("police", "dept", "emp") // 设置需要生成的表名
                                    .entityBuilder()
                                    .enableLombok() // 启用 Lombok
                                    .enableTableFieldAnnotation() // 启用字段注解
                                    .controllerBuilder()
                                    .enableRestStyle(); // 启用 REST 风格
                        })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用 Freemarker 模板引擎
                .execute(); // 执行生成
    }

    public static void main1(String[] args) {
        FastAutoGenerator.create(URL, USERNAME, PASSWORD)
                .globalConfig(
                        builder ->
                                builder.author("段静迪，duanjingdi@163.com")
                                        //                                        .enableSwagger()
                                        // // 开启 swagger 模式
                                        .outputDir("D:\\Work\\tyut\\y24g3\\myboot\\src\\main\\java")
                                        .commentDate("yyyy-MM-dd HH:mm:ss"))
                .packageConfig(
                        builder ->
                                builder.parent("com.neusoft.npi")
                                        .entity("entity")
                                        .mapper("mapper")
                                        .service("service")
                                        .serviceImpl("service.impl")
                                        .xml("mapper.xml"))
                .strategyConfig(builder -> builder.entityBuilder().enableLombok())
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
        System.out.println("Hello World!");
    }
}
